package com.lcf.task;

import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.lcf.system.entity.SysTenantRule;
import com.lcf.system.enums.RuleStatusEnum;
import org.jobrunr.jobs.annotations.Job;
import org.jobrunr.jobs.annotations.Recurring;
import org.springframework.stereotype.Component;

import java.time.LocalDate;

/**
 * 描述：团购规则
 *
 * @author lcf
 * @since 2025/5/5 10:07
 */
@Component
public class TenantRuleTask {
    /**
     * 定时将到期团购规则设置为已结束
     */
    @Job(name = "updateRuleStatus")
    @Recurring(id = "updateRuleStatus", cron = "*/5 * * * *")
    public void updateRuleStatus() {
        Db.lambdaUpdate(SysTenantRule.class)
                .ne(SysTenantRule::getStatus, RuleStatusEnum.END.getCode())
                .le(SysTenantRule::getEndTime, LocalDate.now())
                .set(SysTenantRule::getStatus, RuleStatusEnum.END.getCode())
                .update();
    }
}
